<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>创建新的 Worker 对象池</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="pool.collect.html">« Pool::collect</a></li>
      <li style="float: right;"><a href="pool.resize.html">Pool::resize »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.pool.html">Pool</a></li>
    <li>创建新的 Worker 对象池</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="pool.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Pool::__construct</h1>
  <p class="verinfo">(PECL pthreads &gt;= 2.0.0)</p><p class="refpurpose"><span class="refname">Pool::__construct</span> &mdash; <span class="dc-title">创建新的 Worker 对象池</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-pool.construct-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>Pool::__construct</strong></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$size</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$class</code><span class="initializer"> = ?</span></span>, <span class="methodparam"><span class="type">array</span> <code class="parameter">$ctor</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="class.pool.html" class="type Pool">Pool</a></span></div>

  <p class="para rdfs-comment">
  创建新的 Worker 对象池，但是所对应的线程是延迟创建的的，也就是说，
   直到需要执行任务的时候
   才会创建对应的线程。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-pool.construct-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">size</code></dt>

    <dd>

     <p class="para">
      此 Pool 对象可创建的 Worker 对象的最大数量
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">class</code></dt>

    <dd>

     <p class="para">
      新创建的 Worker 对象的类。
      如果不指定类，那么会使用默认的 <span class="classname"><a href="class.worker.html" class="classname">Worker</a></span> 类。
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">ctor</code></dt>

    <dd>

     <p class="para">
      创建 Worker 对象时所用到的参数，以数组方式传入
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-pool.construct-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
 新创建的 Pool 对象
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-pool.construct-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3343">
    <p><strong>示例 #1 创建 Pool 对象</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">MyWorker&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">Worker&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">__construct</span><span style="color: #007700">(</span><span style="color: #0000BB">Something&nbsp;$something</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">something&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$something</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">run</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/**&nbsp;...&nbsp;**/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">}<br />}<br /><br /></span><span style="color: #0000BB">$pool&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Pool</span><span style="color: #007700">(</span><span style="color: #0000BB">8</span><span style="color: #007700">,&nbsp;\</span><span style="color: #0000BB">MyWorker</span><span style="color: #007700">::class,&nbsp;[new&nbsp;</span><span style="color: #0000BB">Something</span><span style="color: #007700">()]);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$pool</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
object(Pool)#1 (6) {
  [&quot;size&quot;:protected]=&gt;
  int(8)
  [&quot;class&quot;:protected]=&gt;
  string(8) &quot;MyWorker&quot;
  [&quot;workers&quot;:protected]=&gt;
  NULL
  [&quot;work&quot;:protected]=&gt;
  NULL
  [&quot;ctor&quot;:protected]=&gt;
  array(1) {
    [0]=&gt;
    object(Something)#2 (0) {
    }
  }
  [&quot;last&quot;:protected]=&gt;
  int(0)
}
</pre></div>
    </div>
   </div>
  </p>
 </div>


</div></div></div></body></html>